package cn.com.dycc.sys_manage.menusysmanagement.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.sys_manage.menusysmanagement.entity.Menu;
import cn.com.dycc.sys_manage.menusysmanagement.entity.MenuResult;
import cn.com.dycc.sys_manage.menusysmanagement.entity.MenuResultList;
import cn.com.dycc.sys_manage.menusysmanagement.param.MenuListParam;
import cn.com.dycc.sys_manage.menusysmanagement.service.MenuService;
import cn.com.dycc.util.JsonObjectResult;
import cn.com.dycc.util.JsonResult;

/**
 * 
 * Description: 菜单的控制层
 * Author: KevinLee
 * Version: 1.0
 * Create Date Time: 2017年8月6日 下午4:59:28.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/menu")
public class MenuController extends BaseController{
	
	@Resource(name="menuService")
	private MenuService menuService;
	
	//新增菜单
	@RequestMapping("/addmenu.do")
	@ResponseBody
	public JsonObjectResult addMenu(HttpServletRequest request,Menu menu){
		String createMenu = menuService.addMenu(request,menu);
		return new JsonObjectResult(createMenu);
	}
	
	//查询所有的菜单信息,树状
	@RequestMapping("/allmenu.do")
	@ResponseBody
	public JsonObjectResult findAllMenu(HttpServletRequest request,String sys_flag){
		List<Object> list = menuService.findAllMenu(request,sys_flag);
		return new JsonObjectResult(list);
	}
	
	//删除选定的菜单信息
	@RequestMapping("/delmenu.do")
	@ResponseBody
	public JsonObjectResult deleteMenuByMenuNo(String menuNo){
		boolean delMenu = menuService.deleteMenuByMenuNo(menuNo);
		return new JsonObjectResult(delMenu);
	}
	
	//根据id查询菜单信息
	@RequestMapping("/findmenu.do")
	@ResponseBody
	public JsonObjectResult findMenuByMenuNo(String menuNo){
		MenuResult menu = menuService.queryTheMenubyMenuId(menuNo);
		return new JsonObjectResult(menu);
	}
	
	//根据id更新菜单信息
	@RequestMapping("/updatemenu.do")
	@ResponseBody
	public JsonObjectResult updateMenuByMenuNo(Menu menu,HttpServletRequest request){
		String newMenu = menuService.updateMenuByMenuNo(request,menu);
		return new JsonObjectResult(newMenu);
	}
	
	//根据用户id查询用户菜单的信息，用于用户的菜单的显示 pc ,手机 ，微信
	@RequestMapping("/usermenu.do")
	@ResponseBody
	public JsonObjectResult findMenuPermission(HttpServletRequest request,String sys_flag){
		List<Object> list = menuService.findMenuInfoByMap(request,sys_flag);
		return new JsonObjectResult(list);
	}
	
	
	//全部菜单信息  用于查询显示
	@RequestMapping("/selallmenu.do")
	@ResponseBody
	public JsonObjectResult selectAllMenuByTopDeptNo(String sys_flag,HttpServletRequest request){
		List<Map<String,Object>> list = 
				menuService.selectAllMenuByTopDeptNo(request,sys_flag);
		return new JsonObjectResult(list);
	}
	
	
	//全部菜单信息  用于查询显示
	@RequestMapping("/countmenulist.do")
	@ResponseBody
	public JsonObjectResult menuList(HttpServletRequest request,MenuListParam menuListParam){
		String count = menuService.countMenuList(request, menuListParam);
		List<MenuResultList> list = menuService.findMenuList(request, menuListParam);
		return new JsonObjectResult(count, list);
	}
	
	//20180614根据用户id查询用户菜单的信息，用于用户的菜单的显示 pc ,手机 ，微信
	@RequestMapping("/userandmenu.do")
	@ResponseBody
	public JsonObjectResult findMenuAndUserInfo(HttpServletRequest request,String sys_flag){
		List<Object> list = menuService.findMenuAndUserInfo(request,sys_flag);
		return new JsonObjectResult(list);
	}
	
	
}
